/*
 * @Descripttion:
 * @version:
 * @Author: cain
 * @Date: 2022-12-27 15:45:13
 * @LastEditors: Andy
 * @LastEditTime: 2022-12-28 10:23:56
 * @FilePath: \cain-ui\package\radioGroup\radioGroup.tsx
 */
import { defineComponent, provide, toRefs } from "vue";

export default defineComponent({
  name: "CRadioGroup",
  props: {
    modelValue: {
      type: String,
      default: "",
    },
  },
  emits: ["update:modelValue", "change"],
  setup(props, { slots, emit }) {
    const { modelValue } = toRefs(props);

    const radioGroup = "radioGroup" + Math.random();

    const GroupChange = (val: string) => {
      emit("update:modelValue", val);
      emit("change", val);
    };
    provide("value", {
      name: radioGroup,
      value: modelValue,
      GroupChange,
    });

    return () => (
      <div class="radioGroup">{slots.default && slots.default()}</div>
    );
  },
});
